package com.jung.news.service.impl;

import java.util.Map;

import javax.annotation.Resource;

import com.hp.util.Page;
import com.hp.util.PageContext;
import com.hp.xquery.SimpleQuery;
import com.jung.news.dao.NewsDao;
import com.jung.news.dao.NewsHibernateDao;
import com.jung.news.model.News;
import com.jung.news.service.NewsService;

public class NewsServiceImpl implements NewsService {

	private NewsHibernateDao newsHibernateDao;
	private NewsDao newsDao;
	@Resource
	public void setNewsHibernateDao(NewsHibernateDao newsHibernateDao) {
		this.newsHibernateDao = newsHibernateDao;
	}
	@Resource
	public void setNewsDao(NewsDao newsDao) {
		this.newsDao = newsDao;
	}

	public PageContext getEntityPage(PageContext pageContext,
			Map<String, String> queryConditions, String orderProperty,
			String orderMode) {
		SimpleQuery query = newsDao.getSimpleQuery();
    	Page page = newsDao.find(query, pageContext.getPageNumber(), pageContext.getPageSize());
    	pageContext.setPage(page);
    	return pageContext;
	}

	public String addNews(News news) {
		if(newsHibernateDao.addNews(news)){
			return "success";
		}
		return "fail";
	}

	public String deleteNewsById(int id) {
	    News news = newsHibernateDao.getNewsById(id);
	    if(newsHibernateDao.deleteNews(news)){
	    	return "success";
	    }
		return "fail";
	}
	public News findNewsById(int id){
		return newsHibernateDao.getNewsById(id);
	}
	public boolean support(String entityName) {
		return false;
	}
	public News getNewsTheNewest() {
		return newsHibernateDao.getNewsTheNewest();
	}

}
